//
//  XKLTabBarController.m
//  GuiZiShouDuanZi
//
//  Created by xmg on 16/4/24.
//  Copyright © 2016年 xiao_kl. All rights reserved.
//

#import "XKLTabBarController.h"
#import "XKLNewViewController.h"
#import "XKLMeTableViewController.h"
#import "XKLFollowViewController.h"
#import "XKLEssenceViewController.h"
#import "XKLTabBarItem.h"
#import "XKLNavigationController.h"
#import "XKLTopWindow.h"

@implementation XKLTabBarController

-(void)viewDidLoad{
    [super viewDidLoad];
    
    [XKLTopWindow show];
    //添加所有子控制器
    [self addAllChildViewController];
    
    [self setItenTitle];
    
    //替换系统的tabBar
    [self setValue:[[XKLTabBarItem alloc] init] forKey:@"tabBar"];
    
    //设置tabBar背景图片
    [self.tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];
}

-(void)addAllChildViewController{
    
    
    //精华
    XKLEssenceViewController *essenceVC=[[XKLEssenceViewController alloc] init];
    [self addAllNaviChildViewController:essenceVC title:@"精华" selImage:[UIImage imageNamed:@"tabBar_essence_click_icon"] image:[UIImage imageNamed:@"tabBar_essence_icon"]];
    
    
    //新帖
    XKLNewViewController *newVC=[[XKLNewViewController alloc] init];
    [self addAllNaviChildViewController:newVC title:@"新帖" selImage:[UIImage imageNamed:@"tabBar_new_click_icon"] image:[UIImage imageNamed:@"tabBar_new_icon"]];
    
    
    //关注
    XKLFollowViewController *followVC=[[XKLFollowViewController alloc] init];
    [self addAllNaviChildViewController:followVC title:@"关注" selImage:[UIImage imageNamed:@"tabBar_friendTrends_click_icon"] image:[UIImage imageNamed:@"tabBar_friendTrends_icon"]];
    
    //我
    UIStoryboard *story=[UIStoryboard storyboardWithName:@"XKLMeTableViewController" bundle:nil];
    XKLMeTableViewController *meVC=[story instantiateInitialViewController];
    [self addAllNaviChildViewController:meVC title:@"我" selImage:[UIImage imageNamed:@"tabBar_me_click_icon"] image:[UIImage imageNamed:@"tabBar_me_icon"]];
    
}

-(void)addAllNaviChildViewController:(UIViewController *)viewController title:(NSString *)title selImage:(UIImage *)selImage image:(UIImage *)image{
    
    XKLNavigationController *naVC=[[XKLNavigationController alloc] initWithRootViewController:viewController];
    naVC.tabBarItem.title=title;
    naVC.tabBarItem.selectedImage=selImage;
    naVC.tabBarItem.image=image;
    [self addChildViewController:naVC];
    
}



-(void)setItenTitle{
    //去掉文字渲染
    UITabBarItem *item=[UITabBarItem appearance];
    
    NSMutableDictionary *dicM=[NSMutableDictionary dictionary];
    dicM[NSForegroundColorAttributeName]=[UIColor grayColor];
    dicM[NSFontAttributeName]=[UIFont systemFontOfSize:12];
    
    [item setTitleTextAttributes:dicM forState:UIControlStateNormal];
    
    NSMutableDictionary *selDicM=[NSMutableDictionary dictionary];
    dicM[NSForegroundColorAttributeName]=[UIColor darkGrayColor];
    [item setTitleTextAttributes:selDicM forState:UIControlStateSelected];
}
@end
